﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Kinixt
{
    class Ground
    {
        private Model groundModel;

        /// <summary>
        /// Load model of ground
        /// </summary>
        /// <param name="content">content manager containing ground model</param>
        public void Load(ContentManager content)
        {
            groundModel = content.Load<Model>("Ground");
        }

        /// <summary>
        /// Draw model of ground
        /// </summary>
        /// <param name="camera">Camera object currently used</param>
        /// <param name="world">World matrix. For default you can pass identity matrix</param>
        public void Draw(BehindHeadCamera camera, Matrix world)
        {
            Matrix[] transforms = new Matrix[groundModel.Bones.Count];
            groundModel.CopyAbsoluteBoneTransformsTo(transforms);

            foreach (ModelMesh mesh in groundModel.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World = transforms[mesh.ParentBone.Index] * world;
                    effect.View = camera.View;
                    effect.Projection = camera.Projection;
                }
                mesh.Draw();
            }
        }

    }
}
